package com.harboursoftware.xstorage.fs;

import java.io.IOException;

import com.harboursoftware.xstorage.XStorageException;
import com.harboursoftware.xstorage.model.XBucket;
import com.harboursoftware.xstorage.model.XObject;

/**
 * 
 * @author Simon Leung
 * @since 0.1
 */
public interface XFileSystem {
    public boolean isBucketExisted(XBucket bucket) throws XStorageException;
    
    public boolean isBucketEmpty(XBucket bucket) throws BucketNotExistException, XStorageException;
    
    /**
     * 删除失败时抛出XStorageException异常。
     * @param bucket
     * @throws BucketNotExistException
     * @throws BucketNotEmptyException
     * @throws XStorageException
     */
    public void deleteBucket(XBucket bucket) throws BucketNotExistException, BucketNotEmptyException, XStorageException;
    
    /**
     * 参数约束：bucket不能为null,bucket.getOwner()不能返回null.
     * @param bucket
     * @throws BucketAlreadyOwnBySameUserException
     * @throws BucketAlreadyOwnedByOtherUserException
     * @throws IOException
     */
    public void createBucket(XBucket bucket) throws BucketAlreadyOwnedByOtherUserException, XStorageException;
    
    public void putBucketAcp(XBucket bucket) throws BucketNotExistException, XStorageException;
    //TODO: 那个比较好：getBucketACP和loadBucketACP
    public void loadBucketACP(XBucket bucket) throws BucketNotExistException, XStorageException;
    
    public void listObjects(XBucket bucket, String delimiter, String marker, int maxKeys, String prefix) throws BucketNotExistException, XStorageException;
    /**
     * 创建Object,如果该Object已经存在这覆盖它。
     * @param object
     * @throws IOException
     * @return md5 digest
     */
    public String createObject(XObject object) throws XStorageException;
    
    public boolean isObjectExisted(XObject object) throws XStorageException;
    
    //TODO: isObjectExisted(XObject object)和isObjectExisted(String bucket, String objcet)选择一下
    //public boolean isObjectExisted(String bucket, String objcet)  throws IOException;
    
    public void loadObject(XObject object) throws BucketNotExistException, ObjectNotExistException, XStorageException;
    
    public void loadObjectACP(XObject object) throws BucketNotExistException, ObjectNotExistException, XStorageException;
    
    public void loadObjectEtag(XObject object) throws BucketNotExistException, ObjectNotExistException, XStorageException;
    
    /**
     * 删除失败时抛出XStorageException异常。
     * @param object
     * @throws BucketNotExistException
     * @throws ObjectNotExistException
     * @throws XStorageException
     */
    public void deleteObject(XObject object) throws BucketNotExistException, ObjectNotExistException, XStorageException;
    
    
    //public XObject loadObjectACP(XObject object) throws ObjectNotExistException, IOException;
}
